
import { showLoadingToast, closeToast, showSuccessToast, showToast, showNotify, showConfirmDialog } from 'vant'
const env = import.meta.env.MODE;
const version = "v1.0.1"
//主题颜色
const PRIMARY_COLOR = '#5D6568';



// 取消
const CANCEL_COLOR = '#717171';
console.log('\x1b[32m%s\x1b[0m', `扫码器${version}`);
console.log( env);

const globalVal = (globalThis as any);

// 路径前缀
globalVal.API_URI_PREFIX = "/prod-api"
// API 基础路径
globalVal.API_BASE_PATH = 'http://192.168.2.18:8389'
// 开发环境配置
if(env == 'development'){
	globalVal.API_BASE_PATH = "http://192.168.2.18:8389"
}

// 应用名称
globalVal.APP_NAME = "MCM_SCANNER"

// 应用标题
globalVal.APP_TITLE = "加工中心扫码器"

// Toast
globalVal.toast = (message: string) => {
	showToast(message)
}

// success
globalVal.success = (message: string) => {
	showNotify({
		type: 'success',
		message
	})
}

// 错误提示
globalVal.error = (message: string) => {
	showNotify({
		type: 'danger',
		message
	})
}

// Alert
globalVal.alert = (message: string) => {
	showSuccessToast(message);

}

// 显示loading
globalVal.showLoading = (message:string) => {
	showLoadingToast({
		message:message,
		forbidClick: true,
  		loadingType: 'spinner',

	})
}

// 关闭loading
globalVal.hideLoading = () => {
	closeToast();
}



/**
 * 确认框
 */
globalVal.showConfirm =  (config:any) => {
  config.confirmButtonColor = config.confirmColor || PRIMARY_COLOR;
  config.cancelButtonColor = config.cancelColor || CANCEL_COLOR;
  config.title = config.title || '提示'
  showConfirmDialog({
	title:config.title,
	message: config.message || config.content
  }).then(()=>{
	config.confirm && config.confirm();
  })
  .catch(()=> {
	config.cancel && config.cancel();
  })
}
